/**
 * Created with IntelliJ IDEA.
 * Description:
 * Date: 2025-04-08
 * Time: 20:26
 */
public class Main {
    public boolean lemonadeChange(int[] bills) {
        int five = 0;
        int ten = 0;

        for(int i = 0;i < bills.length;i++){
            if(bills[i] == 5){
                five++;
            }else if(bills[i] == 10){
                if(five>=1){
                    five--;
                    ten++;
                }else{
                    return false;
                }
            }else if(bills[i] == 20){
                if(five >= 1 && ten >=1 ){
                    five--;
                    ten--;
                }else if(five >= 3 && ten < 1){
                    five-=3;
                }else{
                    return false;
                }
            }
        }

        return true;
    }

    public boolean lemonadeChange1(int[] bills){
        int five = 0,ten = 0;
        for (int x: bills) {
            if (x == 5){
                five++;
            } else if (x == 10) {
                if (five == 0) {
                    return false;
                }
                five--;ten++;
            }else {
                if (five != 0 && ten != 0){
                    five--;ten--;
                }else if (five >= 3){
                    five -= 3;
                }else {
                    return false;
                }
            }
        }
        return true;
    }
}
